"""
@author:  wangyangang
@contact: wangyangang@wangyangang.com
@site:    https://wangyangang.com
@time:   5/25/20 - 3:37 AM
"""
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'dd%=l$qf)1wi+_6%4%c($r=)09l17o%rk#i2jwmod$vrd+nn%o'

DEBUG = True

ALLOWED_HOSTS = ['*']

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tinymce',
    # 'haystack',
    'djcelery',
    'cart.apps.CartConfig',
    'goods.apps.GoodsConfig',
    'user.apps.UserConfig',
    'orders.apps.OrdersConfig'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'dailyfresh.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'dailyfresh.wsgi.application'

# Database
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dailyfresh',
        'USER': 'root',
        'PASSWORD': '456wyg31',
        'HOST': 'localhost',
        'PORT': '3306',
        'OPTIONS': {'charset': 'utf8mb4'},
    }
}
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
#     }
# }


AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
   os.path.join(BASE_DIR, 'static')
]

# 富文本编辑器tinymce配置
TINYMCE_DEFAULT_CONFIG = {
    # 'theme': 'advance',
    'width': 1000,
    'height': 800
}

AUTH_USER_MODEL = 'user.User'

# # 全文检索框架的配置
# HAYSTACK_CONNECTIONS = {
#     'default': {
#         # 使用whoosh引擎
#         'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
#         #'ENGINE': 'haystack.backends.whoosh_cn_backend.WhooshEngine',
#         # 索引文件路径
#         'PATH': os.path.join(BASE_DIR, 'whoosh_index'),
#     }
# }
# 当添加、修改、删除数据时，自动生成索引
# HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

# 发送邮件配置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# smpt服务地址
# EMAIL_HOST = 'smtp.163.com'
EMAIL_HOST = 'smtpdm.aliyun.com'
# EMAIL_PORT = 25
EMAIL_PORT = 465
# 发送邮件的邮箱
# EMAIL_HOST_USER = 'cool3174@163.com'
EMAIL_HOST_USER = 'mail@wyg.wangyangang.com'
# 在邮箱中设置的客户端授权密码
# EMAIL_HOST_PASSWORD = '456wyg31'
EMAIL_HOST_PASSWORD = '456wygWYG31'
# 收件人看到的发件人
# EMAIL_FROM = '天天生鲜<cool3174@163.com>'
EMAIL_FROM = '天天生鲜<mail@wyg.wangyangang.com>'
EMAIL_USE_SSL = True   # 打开ssl协议

# Django的缓存配置
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://redis:6379/9",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}


LAST_BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# SERVER_IP = '127.0.0.1'

# alipay设置
APP_ID = '2016092900626151'
APP_PRIVATE_KEY_PATH = 'orders/app_private_key.pem'
ALIPAY_PUBLIC_KEY_PATH = 'orders/alipay_public_key.pem'

# 配置登录url地址
LOGIN_URL = '/user/login'  # /accounts/login?next=/user

# 商品列表页/list/type_id/page/页，每页展示的条数
GOODS_COUNT_PER_PAGE = 10

CELERY_ACCEPT_CONTENT = ['pickle']

# 七牛图片文件配置
QINIU_ACCESS_KEY = '38njcdBVfuib-yYeZyUvLKF5paladdibwP8cTzrp'
QINIU_SECRET_KEY = 'wtYp6Mj0hGh1EC7JB7hb1hydbnpS86G8cMbNU1Zr'
QINIU_BUCKET_NAME = 'dailyfresh-cloud'
QINIU_BUCKET_DOMAIN = 'dailyfresh.wyg.wiki'
QINIU_SECURE_URL = False      # 使用http
PREFIX_URL = 'http://'

MEDIA_URL = PREFIX_URL + QINIU_BUCKET_DOMAIN + '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuMediaStorage'

# 日志
from .logging_settings import LOGGING